<?php

namespace Apps\AppApi\Method\Question;

use Apps\AppApi\Method\BaseMethod;
use PhalconPlus\Api\Common\ResultStatus;
use Apps\Common\Models\QuestionFollow;

/**
 * 取消收藏
 */
class UnFollow extends BaseMethod
{
    public function run()
    {
    	if(false == $this->verifyUserAuth()){
    		return false;
    	}

    	$question_id = intval($this->getDataItem('question_id', 0));

		if ($question_id == 0) {
			return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, 'URL参数不全');
		}

		$UserFollow = new QuestionFollow();
		if ($model = $UserFollow->findFirst("question_id = {$question_id} and user_id = {$this->getUserAuth()->userId}")) {
			$model->delete();
			$this->setResult(['success' => 1, 'message' => '取消收藏成功']);
		} else {
			$this->setResult(['success' => 2, 'message' => '取消收藏失败']);
		}
    }


}